﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ROOTNET.WinForms;
using ROOTNET.Interface;

namespace RootfusBuiltinAddins.THist1D
{
    /// <summary>
    /// Interaction logic for THist1DUINormal.xaml
    /// </summary>
    public partial class THist1DUINormal : UserControl
    {
        TCanvasControl _cntrl = null;
        public THist1DUINormal()
        {
            InitializeComponent();
            
            _cntrl = new TCanvasControl();
            formsROOT.Child = _cntrl;
        }

        /// <summary>
        /// Draw only one thing on the canvas - what we are given. Will erase
        /// anything else that was up there.
        /// </summary>
        /// <param name="obj"></param>
        public void Draw(NTObject obj)
        {
            _cntrl.DrawOnly(obj);
            if (obj == null)
            {
                _cntrl.Canvas.UseCurrentStyle();
            }
        }

        /// <summary>
        /// Add something new to the canvas.
        /// </summary>
        /// <param name="obj"></param>
        internal void DrawSame(NTObject obj)
        {
            _cntrl.DrawSame(obj);
        }

        /// <summary>
        /// Returns some particular primitive.
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        internal NTObject GetPrimative(string p)
        {
            return _cntrl.Canvas.GetPrimitive(p);
        }

        /// <summary>
        /// Force a re-draw of everything!
        /// </summary>
        internal void Update()
        {
            _cntrl.Canvas.Modified();
        }

        /// <summary>
        /// Save the canvas as a file.
        /// </summary>
        /// <param name="SaveAsFilename"></param>
        internal void SaveCanvasAsFile(string fname)
        {
            if (_cntrl != null)
            {
                _cntrl.Canvas.Print(fname);
            }
        }
    }
}
